package com.yixin.controller;

import com.yixin.entity.Permission;
import com.yixin.entity.Result;
import com.yixin.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/permissions")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @PostMapping
    public Result add(@RequestBody Permission permission) {
        permissionService.add(permission);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody Permission permission) {
        permissionService.update(permission);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        permissionService.deleteById(id);
        return Result.success();
    }

    @GetMapping
    public Result findAll() {
        return Result.success(permissionService.findAll());
    }
}
